/**
 * 
 */
package com.sx.cms.action;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.alibaba.fastjson.JSONArray;
import com.opensymphony.xwork2.ModelDriven;
import com.sx.cms.biz.ICityInfoBiz;
import com.sx.cms.entity.CityInfoEntity;
import com.sx.core.CoreAction;
import com.sx.rbac.entity.SysUserEntity;

/**
 * @author Administrator
 *
 */
@SuppressWarnings("serial")
public class CityInfoAction extends CoreAction implements ModelDriven<CityInfoEntity> {
	private CityInfoEntity cityinfo = new CityInfoEntity();
	private Log log = LogFactory.getLog(this.getClass());
	private ICityInfoBiz cityinfobiz;
	/**
	 *根据编号经销商信息获取用户数量 
	 **/
	public void queryAgenterUserCount(){
		Integer count = new Integer(0);
		try {
			count = cityinfobiz.queryAgenterUserCount(cityinfo);
		} catch (Exception e) {
			// TODO: handle exception
			log.error("仅获取经销商信息数量",e);
		}
		outJsonString(""+count);
	}
	/**
	 *根据编号获取经销商用户信息
	 **/
	public void queryAgenterUserInfo(){
		String str = "";
		try {
			List<SysUserEntity> list = cityinfobiz.queryAgenterUserInfo(cityinfo);
			str = JSONArray.toJSONString(list);
		} catch (Exception e) {
			log.error("仅获取经销商信息数量",e);
		}
		outJsonString(str);
	}
	
	
	/**
	 *根据编号获取城市信息
	 *或经销商信息 
	 **/
	public void getCityInfoOrAgenterInfoById(){
		Integer count = new Integer(0);
		try {
			count = cityinfobiz.findCityInfosTotal(cityinfo);
		} catch (Exception e) {
			// TODO: handle exception
			log.error("仅获取经销商信息数量",e);
		}
		outJsonString(""+count);
	}
	/**
	 * 仅获取经销商信息
	 **/
	public void getCityAgenterInfo(){
		String str = "{totalCount:0,data:[]}";
		try {
			Integer count = cityinfobiz.findCityInfosTotal(cityinfo);
			List<CityInfoEntity> list = cityinfobiz.findCityInfosByPaging(cityinfo);
			str = "{totalCount:"+count+",data:"+JSONArray.toJSONString(list)+"}";
		} catch (Exception e) {
			// TODO: handle exception
			log.error("仅获取经销商信息带分页",e);
		}
		outJsonString(str);
	}
	/**
	 * 获取经销商数据信息
	 **/
	public void getCityInfo(){
		String str = "[]";
		try {
			List<CityInfoEntity> list = cityinfobiz.findCityInfos(cityinfo);
			str = JSONArray.toJSONString(list);
		} catch (Exception e) {
			log.error("获取经销商数据信息出错!",e);
			// TODO: handle exception
		}
		outJsonString(str);
	}
	/* (non-Javadoc)
	 * @see com.opensymphony.xwork2.ModelDriven#getModel()
	 */
	public CityInfoEntity getModel() {
		// TODO Auto-generated method stub
		return cityinfo;
	}
	/**
	 * @return the cityinfobiz
	 */
	public ICityInfoBiz getCityinfobiz() {
		return cityinfobiz;
	}
	/**
	 * @param cityinfobiz the cityinfobiz to set
	 */
	public void setCityinfobiz(ICityInfoBiz cityinfobiz) {
		this.cityinfobiz = cityinfobiz;
	}
	
}
